#!/bin/bash # It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Desktop Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description - Script to fetch wifi details # Configuration Type - COMPUTER services=$(networksetup -listnetworkserviceorder | grep 'Hardware Port') while read line; do sname=$(echo $line | awk -F "(, )|(: )|[)]" '{print $2}') sdev=$(echo $line | awk -F "(, )|(: )|[)]" '{print $4}') if [ -n "$sdev" ]; then ifout="$(ifconfig $sdev 2>/dev/null)" echo "$ifout" | grep 'status: active' > /dev/null 2>&1 rc="$?" if [ "$rc" -eq 0 ]; then currentservice="$sname" currentdevice="$sdev" currentmac=$(echo "$ifout" | awk '/ether/{print $2}') echo "Service name: $currentservice" echo "Device: $currentdevice" echo "Ethernet Address: $currentmac" fi fi done <<< "$(echo "$services")" if [ -z "$currentservice" ]; then >&2 echo "Could not find current service" exit 1 fi